// pages/userList/userList.js
var api = require('../../request/api');
import util from '../../utils/util';
import Toast from '../../vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderId:null,
    userList:[],
    showpopup:false,
    userInfo:null,
    tipsColor:null,
  },
  onClose(){
    this.setData({
      showpopup:false
    })
  },
  godetail(e){
    var detail = e.currentTarget.dataset.variable;
    console.log(detail);
    this.getUseringo(detail.userId)
  },
  checCreditScore(creditScore) {
    var tips = "";
    var color = "";
    if (creditScore > 100){
      tips = "非常棒！请继续保持！";
      color = "#0984e3";
    }else if(creditScore > 80 && creditScore <= 100){
      tips = "真不错！还可以加油哦！";
      color = "#00b894";
    }else if(creditScore > 60 && creditScore <= 80){
      tips = "要加油了哦！";
      color = "#ffeaa7";
    }else if(creditScore < 60){
      tips = "同学，进步空间还很大呢";
      color = "#d63031";
    }
    this.setData({
      tips: tips,
      tipsColor:color
    })
  },
  getUseringo(id){
    util.post(api.user.queryOne,{userId:id}).then(res =>{
      if(res.code == 200){
        console.log(res);
        this.setData({
          userInfo:res.data,
          showpopup:true
        })
        this.checCreditScore(res.data.creditScore);
      }else{
        Toast.fail(res.message)
      }
    })
  },
  getList(){
    util.post(api.order.qryOrderUser,{pageSize:99,queryObj:{orderId:this.data.orderId}}).then(res =>{
      if(res.code == 200){
        this.setData({
          userList:res.data.list
        })
      }else{
        Toast.fail(res.message)
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  
  onLoad: function (options) {
    console.log(options)
    this.setData({
      orderId: options.orderId,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      this.getList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.setData({
      userInfo:null
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})